<?php

namespace com\aristo\ingenieros\util;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of constAccount
 *
 * @author ARISTO INGENIEROS
 */
class constAccount {

    //*****
    public static $_GET_CUENTAS = 1; //*
    public static $_GET_CUENTA = 2;
    public static $_PUT_CUENTA = 3;
    public static $_POST_CUENTA = 4;
    public static $_DELETE_CUENTA = 5;
    //*****
    public static $_GET_PERSONALES = 6;
    public static $_GET_PERSONAL = 7;
    public static $_PUT_PERSONAL = 8;
    public static $_POST_PERSONAL = 9;
    public static $_DELETE_PERSONAL = 10;
    //*****
    public static $_GET_CONCEPTOS = 11;
    public static $_GET_CONCEPTO = 12;
    public static $_PUT_CONCEPTO = 13;
    public static $_POST_CONCEPTO = 14;
    public static $_DELETE_CONCEPTO = 15;
    //*****
    public static $_GET_NOTAS = 16;
    public static $_GET_NOTA = 17;
    public static $_PUT_NOTA = 18;
    public static $_POST_NOTA = 19;
    public static $_DELETE_NOTA = 20;
    //*****
    public static $_GET_MAXNRORECIBO = 21;
    public static $_POST_RECIBO = 22;
    public static $_GET_RECIBOS = 23;
    public static $_DELETE_DOCUMENTO = 24;
    public static $_IMPRIMIR_RECIBO = 25;
    //*****
    public static $_GET_MAXORDEN = 26;
    public static $_POST_ORDEN = 27;
    public static $_IMPRIMIR_ORDEN = 28;
    public static $_GET_COMPROBANTES_PENDIENTES = 29;
    //*****
    public static $_GET_MAXCOMPROBANTE = 30;
    public static $_GET_ORDENCOMPRA = 31;
    public static $_POST_COMPROBANTE = 32;
    public static $_IMPRIMIR_COMPROBANTE = 33;
    public static $_GET_ORDENES = 34;
    //*****
    public static $_IMPRIMIR_LIBRODIARIO = 35;
    public static $_IMPRIMIR_LIBROCAJA = 36;
    public static $_IMPRIMIR_LIBROBANCO = 37;
    public static $_IMPRIMIR_LIBROMAYOR = 38;
    public static $_IMPRIMIR_LIBROBALANCEGENERAL = 39;

    public static function getNULL($param) {
        return ($param != "NULL") ? $param : "-";
    }

    public static function NumerosALetras($monto) {
        $maximo = pow(10, 9);
        $unidad = array(1 => "UNO", 2 => "DOS", 3 => "TRES", 4 => "CUATRO", 5 => "CINCO", 6 => "SEIS", 7 => "SIETE", 8 => "OCHO", 9 => "NUEVE");
        $decena = array(10 => "DIEZ", 11 => "ONCE", 12 => "DOCE", 13 => "TRECE", 14 => "CATORCE", 15 => "QUINCE", 20 => "VEINTE", 30 => "TREINTA", 40 => "CUARENTA", 50 => "CINCUENTA", 60 => "SESENTA", 70 => "SETENTA", 80 => "OCHENTA", 90 => "NOVENTA");
        $prefijo_decena = array(10 => "DIECI", 20 => "VEINTI", 30 => "TREINTA Y ", 40 => "CUARENTA Y ", 50 => "CINCUENTA Y ", 60 => "SESENTA Y ", 70 => "SETENTA Y ", 80 => "OCHENTA Y ", 90 => "NOVENTA Y ");
        $centena = array(100 => "CIEN", 200 => "DOSCIENTOS", 300 => "TRESCIENTOS", 400 => "CUANTROCIENTOS", 500 => "QUINIENTOS", 600 => "SEISCIENTOS", 700 => "SETECIENTOS", 800 => "OCHOCIENTOS", 900 => "NOVECIENTOS");
        $prefijo_centena = array(100 => "CIENTO ", 200 => "DOSCIENTOS ", 300 => "TRESCIENTOS ", 400 => "CUANTROCIENTOS ", 500 => "QUINIENTOS ", 600 => "SEISCIENTOS ", 700 => "SETECIENTOS ", 800 => "OCHOCIENTOS ", 900 => "NOVECIENTOS ");
        $sufijo_miles = "MIL";
        $sufijo_millon = "UN MILLON";
        $sufijo_millones = "MILLONES";

        //echo var_dump($monto); die;

        $base = strlen(strval($monto));
        $pren = intval(floor($monto / pow(10, $base - 1)));
        $prencentena = intval(floor($monto / pow(10, 3)));
        $prenmillar = intval(floor($monto / pow(10, 6)));
        $resto = $monto % pow(10, $base - 1);
        $restocentena = $monto % pow(10, 3);
        $restomillar = $monto % pow(10, 6);

        if (!$monto)
            return "";

        if (is_int($monto) && $monto > 0 && $monto < abs($maximo)) {
            switch ($base) {
                case 1: return $unidad[$monto];
                case 2: return array_key_exists($monto, $decena) ? $decena[$monto] : $prefijo_decena[$pren * 10] . constAccount::NumerosALetras($resto);
                case 3: return array_key_exists($monto, $centena) ? $centena[$monto] : $prefijo_centena[$pren * 100] . constAccount::NumerosALetras($resto);
                case 4: case 5: case 6: return ($prencentena > 1) ? constAccount::NumerosALetras($prencentena) . " " . $sufijo_miles . " " . constAccount::NumerosALetras($restocentena) : $sufijo_miles . " " . constAccount::NumerosALetras($restocentena);
                case 7: case 8: case 9: return ($prenmillar > 1) ? constAccount::NumerosALetras($prenmillar) . " " . $sufijo_millones . " " . constAccount::NumerosALetras($restomillar) : $sufijo_millon . " " . constAccount::NumerosALetras($restomillar);
            }
        } else {
            echo "ERROR con el numero - $monto<br/> Debe ser un numero entero menor que " . number_format($maximo, 0, ".", ",") . ".";
        }

        //return $texto;
    }

    public static function MontoMonetarioEnLetras($monto) {
        $monto = str_replace(',', '', $monto); //ELIMINA LA COMA

        $pos = strpos($monto, '.');

        if ($pos == false) {
            $monto_entero = $monto;
            $monto_decimal = '00';
        } else {
            $monto_entero = substr($monto, 0, $pos);
            $monto_decimal = substr($monto, $pos, strlen($monto) - $pos);
            $monto_decimal = $monto_decimal * 100;
        }

        $monto = (int) ($monto_entero);

        $texto_con = " CON $monto_decimal/100 NUEVOS SOLES";

        return constAccount::NumerosALetras($monto) . $texto_con;
    }

    public static function getMes($nromes) {
        if ($nromes == "1") {
            return "ENERO";
        }
        if ($nromes == "2") {
            return "FEBRERO";
        }
        if ($nromes == "3") {
            return "MARZO";
        }
        if ($nromes == "4") {
            return "ABRIL";
        }
        if ($nromes == "5") {
            return "MAYO";
        }
        if ($nromes == "6") {
            return "JUNIO";
        }
        if ($nromes == "7") {
            return "JULIO";
        }
        if ($nromes == "8") {
            return "AGOSTO";
        }
        if ($nromes == "9") {
            return "SEPTIEMBRE";
        }
        if ($nromes == "10") {
            return "OCTUBRE";
        }
        if ($nromes == "11") {
            return "NOVIEMBRE";
        }
        if ($nromes == "12") {
            return "DOCIEMBRE";
        }
        return "NULL";
    }

}